package com.xiaolin.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName TestPattern
 * @Description TODO
 * @Detail 测试正则表达式
 * @Author MyPC
 * @Date 2020/9/27
 * @Version 1.0
 */
public class TestPattern {
    public static void main(String[] args) {
        System.out.println(isMatch("hello xiaolin",".*hello.*"));
        System.out.println(isMatch2("hello xiaolin",".*hello.*"));
    }


    /**
     * 检查是否匹配2
     * @param content
     * @param regex
     * @return
     */
    public static boolean isMatch2(String content,String regex){
        //获取Pattern对象
        Pattern pattern = Pattern.compile(regex);
        //获取Matcher对象
        Matcher matcher = pattern.matcher(content);
        return matcher.find();
    }


    /**
     * 检查是否匹配1
     * @param content
     * @param regex
     * @return
     */
    public static boolean isMatch(String content,String regex){
        return Pattern.matches(regex, content);
    }
}
